package publish

import (
	"context"
	"encoding/json"
	"group-card/api/internal/types"
	"group-card/common/response"
	"group-card/rpc/card/cardclient"

	"github.com/zeromicro/go-zero/core/logx"
	"group-card/api/internal/svc"
)

type PublishStopLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPublishStopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishStopLogic {
	return &PublishStopLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

//region TODO: 批次停用 Author:LiuYanLin Date:2023/04/05 周三 13:26

func (l *PublishStopLogic) PublishStop(req *types.StopPublishRequest) (resp *types.PublishResponse, err error) {
	_, err = l.svcCtx.Card.PublishStop(l.ctx, &cardclient.PublishStopRequest{
		Id: req.Id,
	})

	if err != nil {
		reqStr, _ := json.Marshal(req)
		logx.WithContext(l.ctx).Errorf("批次停用失败,参数:%s,异常:%s", reqStr, err.Error())
		return &types.PublishResponse{Code: response.ErrCode, Message: response.StrErr(err.Error())}, nil
	}

	return &types.PublishResponse{
		Code:    response.SuccessCode,
		Message: "批次停用成功",
	}, nil
}

//endregion
